package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Parameter;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link Parameter} creation command
 * @author Remi Schnekenburger
 */
public class ParameterCreateCommandTest extends PapyrusCommandTest {

	private Operation operation;

	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public ParameterCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		// creates a class
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Class.class,model);
		stack.execute(papyrusCommand);
		org.eclipse.uml2.uml.Class class_ = (org.eclipse.uml2.uml.Class)((UMLElementCreateCommand)papyrusCommand).getElement();
		// creates an operation
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Operation.class,class_);
		stack.execute(papyrusCommand);
		this.operation= (org.eclipse.uml2.uml.Operation)((UMLElementCreateCommand)papyrusCommand).getElement();
		
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Parameter.class, this.operation);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		// execute command
		stack.execute(papyrusCommand);
		Element clazz=operation.getOwnedParameter("param_0", null);
		assertNotNull("the parameter is created",clazz);
		assertTrue("this is not a parameter",((clazz)instanceof Parameter));

		// undo command
		stack.undo();
		assertNull("the parameter exist!", operation.getOwnedParameter("param_0", null));

		// redo command
		stack.redo();
		clazz=operation.getOwnedParameter("param_0", null);
		assertNotNull("the parameter is re-added to operation",clazz);
		assertTrue("this is not a parameter",((clazz)instanceof Parameter));

	}

}
